package classes.Commands
{
	import components.editor.c_baseEditor;
	import components.editor.c_baseElement;
	import components.editor.c_bitmapElement;
	
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	
	public class c_flipCommand extends c_baseBitmapCommand {
		private var _horyType: Boolean;
		public function c_flipCommand(a_editor:c_baseEditor, a_element: c_bitmapElement, horyType: Boolean=true) {
			super(a_editor, a_element);
			_horyType = horyType;
		}
		
		private function get flipMatrix(): Matrix {
			return _horyType?(new Matrix(-1, 0, 0, 1, bmd.width)):(new Matrix(1, 0, 0, -1, 0, bmd.height));
		}
		
		protected function flip(): void {
			var a_tmp: BitmapData = new BitmapData(bmd.width, bmd.height, bmd.transparent, 0);
			a_tmp.draw(bmd, flipMatrix);
			bmd.dispose();
			bmd = a_tmp;
		}
		
		override public function Execute():void {
			flip();
		}
		
		override public function unExecute():void {
			flip();
		}
	}
}